<?php
namespace App\Http\Requests\Trade\Supply;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class MyListRequest extends FormRequest
{

    /**
     * 状态（上架）
     */
    const STATUS_DEFAULT = 1;

    /**
     * 状态（下架）
     */
    const STATUS_LEAVE = 2;

    /**
     * 状态（驳回）
     */
    const STATUS_REJECT = 3;

    /**
     * 获取状态数组
     */
    public static function getStatusList()
    {
        return [
            self::STATUS_DEFAULT,
            self::STATUS_LEAVE,
            self::STATUS_REJECT
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'page' => 'nullable|integer|between:1,10000',
            'page_size' => 'nullable|integer|between:1,100',
            'status' => [
                'nullable',
                Rule::in(self::getStatusList())
            ]
        ];
    }

    /**
     * 获取已定义的验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'status.in' => ':attribute 必须在[' . implode(',', self::getStatusList()) . ']中'
        ];
    }
}
